# author:欧阳亨杰
# datetime:2022/5/3 16:14
# author:欧阳亨杰
# datetime:2022/5/3 15:38
import unittest
import requests
import pandas as pd
import ddt

url = "http://localhost:8081/"

file = pd.read_csv('../data/add_test.csv')
df = pd.DataFrame(file)
data = df.to_dict(orient='records')


@ddt.ddt
class AddTest(unittest.TestCase):
    @ddt.data(*data)
    def testAddSuccess(self, data):
        # 结果
        result = requests.post(url=url + "discussPost/addPost", data=data).json()
        print(result)
        if (data.get('state') == 1):
            self.assertEqual(0, result.get("code"))
        else:
            self.assertNotEqual(0, result.get("code"))


if __name__ == '__main__':
    unittest.main()

